package com.xiaoshuidi.cloud.module.rooms.convert.roomel;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.RoomelCreateReqVO;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.RoomelUpdateReqVO;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.UpdateRoomelEntiry;
import com.xiaoshuidi.cloud.module.rooms.pojo.roomel.RoomelEntity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class MyRoomelConvert {
    public static List<RoomelEntity> roomelCreateReqVOToRoomelEntity(List<RoomelCreateReqVO> roomelCreateReqVOS) {
        List<RoomelEntity> roomelEntities = new ArrayList<>();
        for (RoomelCreateReqVO bean : roomelCreateReqVOS) {
            if ( bean == null ) {
                return null;
            }

            RoomelEntity roomelEntity = new RoomelEntity();

            roomelEntity.setApartmentAreaGeo( RoomelConvert.latlonToApartmentAreaGeo( bean ) );
            roomelEntity.setApartmentGeo( RoomelConvert.latlonToApartmentGeo( bean ) );
            roomelEntity.setTenantinfo( bean.getTenantinfo() );
            roomelEntity.setId( bean.getId() );
            roomelEntity.setFullName( bean.getFullName() );
            roomelEntity.setRoomHouseName( bean.getRoomHouseName() );
            roomelEntity.setRoomHouseNo( bean.getRoomHouseNo() );
            roomelEntity.setHouseNo( bean.getHouseNo() );
            roomelEntity.setCheckCode( bean.getCheckCode() );
            if ( bean.getCheckCodeInDate() != null ) {
                LocalDateTime localDateTime = DateUtil.parseLocalDateTime(bean.getCheckCodeInDate(), "yyyy-MM-dd");
                roomelEntity.setCheckCodeInDate( localDateTime );
            }
            roomelEntity.setSuperId( bean.getSuperId() );
            roomelEntity.setApartmentAreaId( bean.getApartmentAreaId() );
            roomelEntity.setStreet( bean.getStreet() );
            roomelEntity.setApartmentAreaName( bean.getApartmentAreaName() );
            roomelEntity.setApartmentName( bean.getApartmentName() );
            roomelEntity.setApartmentId( bean.getApartmentId() );
            roomelEntity.setIsConcentrated( bean.getIsConcentrated() );
            roomelEntity.setSourceType( bean.getSourceType() );
            roomelEntity.setFloorId( bean.getFloorId() );
            roomelEntity.setBuildingNo( bean.getBuildingNo() );
            roomelEntity.setUnitNo( bean.getUnitNo() );
            roomelEntity.setFloorNo( bean.getFloorNo() );
            roomelEntity.setFloorSum( bean.getFloorSum() );
            roomelEntity.setCity( bean.getCity() );
            roomelEntity.setDistrict( bean.getDistrict() );
            roomelEntity.setAddress( bean.getAddress() );
            roomelEntity.setResidence( bean.getResidence() );
            roomelEntity.setBedroomNum( bean.getBedroomNum() );
            roomelEntity.setLivingroomNum( bean.getLivingroomNum() );
            roomelEntity.setKitchenNum( bean.getKitchenNum() );
            roomelEntity.setToiletNum( bean.getToiletNum() );
            roomelEntity.setBalcony( bean.getBalcony() );
            roomelEntity.setRoomHouseTypeId( bean.getRoomHouseTypeId() );
            roomelEntity.setRoomHouseTypeName( bean.getRoomHouseTypeName() );
            roomelEntity.setLayoutId( bean.getLayoutId() );
            roomelEntity.setLayoutName( bean.getLayoutName() );
            roomelEntity.setFacetoType( bean.getFacetoType() );
            roomelEntity.setTenantMainName( bean.getTenantMainName() );
            roomelEntity.setIsWhole( bean.getIsWhole() );
            roomelEntity.setSpace( bean.getSpace() );
            roomelEntity.setPrice( bean.getPrice() );
            roomelEntity.setDecoration( bean.getDecoration() );
            roomelEntity.setHouseState( bean.getHouseState() );
            roomelEntity.setIsScheduled( bean.getIsScheduled() );
            roomelEntity.setContractInfo( bean.getContractInfo() );
            roomelEntity.setBillInfo( bean.getBillInfo() );
            roomelEntity.setPreInfo( bean.getPreInfo() );
            roomelEntity.setTenantId( bean.getTenantId() );
            roomelEntity.setIsLock( bean.getIsLock() );
            roomelEntity.setPublicFacilities( bean.getPublicFacilities() );
            roomelEntity.setDeptId( bean.getDeptId() );
            roomelEntity.setRoomType( bean.getRoomType() );
            roomelEntity.setRoomAreaId( bean.getRoomAreaId() );
            roomelEntity.setCreateTime( bean.getCreateTime() );
            roomelEntity.setIsStop( bean.getIsStop() );
            roomelEntity.setIsClean(bean.getIsClean());
            roomelEntity.setIsRepair(bean.getIsRepair());
            roomelEntity.setRoomUsage(bean.getRoomUsage());

            if(ObjectUtil.isAllNotEmpty(bean.getApartmentAreaLat(), bean.getApartmentAreaLon())){
                String geo = bean.getApartmentAreaLat() + "," + bean.getApartmentAreaLon();
                roomelEntity.setApartmentAreaGeo(geo);
            }
            if(ObjectUtil.isAllNotEmpty(bean.getApartmentLat(), bean.getApartmentLon())){
                String geo = bean.getApartmentLat() + "," + bean.getApartmentLon();
                roomelEntity.setApartmentGeo(geo);
            }

            roomelEntities.add(roomelEntity);
        }

        return roomelEntities;
    }

    public static List<RoomelEntity> RoomelUpdateReqVOToRoomelEntity(List<RoomelUpdateReqVO> reqVOList) {
        List<RoomelEntity> roomelEntities = new ArrayList<>();
        for (RoomelUpdateReqVO bean : reqVOList) {
            if ( bean == null ) {
                return null;
            }

            RoomelEntity roomelEntity = new RoomelEntity();

            roomelEntity.setApartmentAreaGeo( RoomelConvert.latlonToApartmentAreaGeo( bean ) );
            roomelEntity.setApartmentGeo( RoomelConvert.latlonToApartmentGeo( bean ) );
            roomelEntity.setTenantinfo( bean.getTenantinfo() );
            roomelEntity.setId( bean.getId() );
            roomelEntity.setFullName( bean.getFullName() );
            roomelEntity.setRoomHouseName( bean.getRoomHouseName() );
            roomelEntity.setRoomHouseNo( bean.getRoomHouseNo() );
            roomelEntity.setHouseNo( bean.getHouseNo() );
            roomelEntity.setCheckCode( bean.getCheckCode() );
            if ( bean.getCheckCodeInDate() != null ) {
                LocalDateTime localDateTime = DateUtil.parseLocalDateTime(bean.getCheckCodeInDate(), "yyyy-MM-dd");
                roomelEntity.setCheckCodeInDate( localDateTime );
            }
            roomelEntity.setSuperId( bean.getSuperId() );
            roomelEntity.setApartmentAreaId( bean.getApartmentAreaId() );
            roomelEntity.setStreet( bean.getStreet() );
            roomelEntity.setApartmentAreaName( bean.getApartmentAreaName() );
            roomelEntity.setApartmentName( bean.getApartmentName() );
            roomelEntity.setApartmentId( bean.getApartmentId() );
            roomelEntity.setIsConcentrated( bean.getIsConcentrated() );
            roomelEntity.setSourceType( bean.getSourceType() );
            roomelEntity.setFloorId( bean.getFloorId() );
            roomelEntity.setBuildingNo( bean.getBuildingNo() );
            roomelEntity.setUnitNo( bean.getUnitNo() );
            roomelEntity.setFloorNo( bean.getFloorNo() );
            roomelEntity.setFloorSum( bean.getFloorSum() );
            roomelEntity.setCity( bean.getCity() );
            roomelEntity.setDistrict( bean.getDistrict() );
            roomelEntity.setAddress( bean.getAddress() );
            roomelEntity.setResidence( bean.getResidence() );
            roomelEntity.setBedroomNum( bean.getBedroomNum() );
            roomelEntity.setLivingroomNum( bean.getLivingroomNum() );
            roomelEntity.setKitchenNum( bean.getKitchenNum() );
            roomelEntity.setToiletNum( bean.getToiletNum() );
            roomelEntity.setBalcony( bean.getBalcony() );
            roomelEntity.setRoomHouseTypeId( bean.getRoomHouseTypeId() );
            roomelEntity.setRoomHouseTypeName( bean.getRoomHouseTypeName() );
            roomelEntity.setLayoutId( bean.getLayoutId() );
            roomelEntity.setLayoutName( bean.getLayoutName() );
            roomelEntity.setFacetoType( bean.getFacetoType() );
            roomelEntity.setTenantMainName( bean.getTenantMainName() );
            roomelEntity.setIsWhole( bean.getIsWhole() );
            roomelEntity.setSpace( bean.getSpace() );
            roomelEntity.setPrice( bean.getPrice() );
            roomelEntity.setDecoration( bean.getDecoration() );
            roomelEntity.setHouseState( bean.getHouseState() );
            roomelEntity.setIsScheduled( bean.getIsScheduled() );
            roomelEntity.setContractInfo( bean.getContractInfo() );
            roomelEntity.setBillInfo( bean.getBillInfo() );
            roomelEntity.setPreInfo( bean.getPreInfo() );
            roomelEntity.setTenantId( bean.getTenantId() );
            roomelEntity.setIsLock( bean.getIsLock() );
            roomelEntity.setPublicFacilities( bean.getPublicFacilities() );
            roomelEntity.setDeptId( bean.getDeptId() );
            roomelEntity.setRoomType( bean.getRoomType() );
            roomelEntity.setRoomAreaId( bean.getRoomAreaId() );
            roomelEntity.setCreateTime( bean.getCreateTime() );

            if(ObjectUtil.isAllNotEmpty(bean.getApartmentAreaLat(), bean.getApartmentAreaLon())){
                String geo = bean.getApartmentAreaLat() + "," + bean.getApartmentAreaLon();
                roomelEntity.setApartmentAreaGeo(geo);
            }
            if(ObjectUtil.isAllNotEmpty(bean.getApartmentLat(), bean.getApartmentLon())){
                String geo = bean.getApartmentLat() + "," + bean.getApartmentLon();
                roomelEntity.setApartmentGeo(geo);
            }

            roomelEntities.add(roomelEntity);
        }
        return roomelEntities;
    }

    public static void convert(UpdateRoomelEntiry updateRoomelEntiry, RoomelEntity roomel) {
            roomel.setTenantinfo(updateRoomelEntiry.getTenantinfo());
            roomel.setContractInfo(updateRoomelEntiry.getContractInfo());
            roomel.setIsLock(updateRoomelEntiry.getIsLock());
            roomel.setHouseState(updateRoomelEntiry.getHouseState());
            Boolean isClean = updateRoomelEntiry.getIsClean();
        if (ObjectUtil.isNotEmpty(isClean)) {
            roomel.setIsClean(isClean);
        }

    }
}
